package com.homson.servicedomain.domain.account;

import com.homson.coreservice.servicecommon.vo.AccountVO;
import com.homson.coreservice.servicecommon.vo.Operation;
import com.homson.coreservice.serviceinfrastructure.dto.AccountDto;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author: homson_leo
 * @contact: hey_超级巨星（Homson_Leo）- 刘泓岑 1196816884@qq.com
 * @time: 2025/11/15 5:26 PM
 **/
@Component
@Slf4j
public class AccountRenderCommand {
    @Autowired
    private AccountQueryCommand accountQueryCommand;
    
    public List<AccountVO> queryAccountListRender(Long userId, Integer pageNum, Integer pageSize) {
        try {
            List<AccountDto> accountDtos = accountQueryCommand.queryAllAccountList(userId, pageNum, pageSize);
            
            List<Operation> operations = new ArrayList<>();
            operations.add(new Operation("记账", 1, ""));
            
            List<AccountVO> accountVOList = new ArrayList<>();
            for (AccountDto each : accountDtos) {
                AccountVO accountVO = new AccountVO();
                accountVO.setAccountId(each.getAccountId());
                accountVO.setAccountName(each.getAccountName());
                accountVO.setAccountType(each.getAccountType().getDesc());
                accountVO.setBalance(each.getBalance());
                accountVO.setOperationList(operations);
                accountVO.setUpdateTime(each.getUpdateTime());
                accountVOList.add(accountVO);
            }
            return accountVOList;
        } catch (Exception e) {
            log.error(AccountRenderCommand.class.getSimpleName(),"渲染账户详情异常",e);
            return Collections.emptyList();
        }
    }
}
